package net.monare.mifss.evn;

import com.vaadin.ui.Button;
import com.vaadin.ui.Notification;
import net.monare.mifss.admin.ui.win.AddNewStorageSetWindow;
import net.monare.mifss.admin.ui.win.ConfigureStorageWindow;
import net.monare.mifss.exceptions.StorageServiceException;

/**
 * Created by jernej on 4/10/14.
 */

public class AddNewStorageSetListener extends BasicMifssListener implements Button.ClickListener {

    private ConfigureStorageWindow configureStorageWindow;
    private AddNewStorageSetWindow parent;

    public AddNewStorageSetListener(ConfigureStorageWindow configureStorageWindow, AddNewStorageSetWindow parent) {
        this.configureStorageWindow = configureStorageWindow;
        this.parent = parent;
    }

    @Override
    public void buttonClick(Button.ClickEvent event) {

        try {

            // todo: lock button

            getMifssHolder().getStorageService().createStorageSetDefintion(parent.getStorageSetDef());
            parent.close();
            configureStorageWindow.resetAllPanes();

        } catch (StorageServiceException e) {
            Notification.show("error occurred while trying to add new storage set: " + e.getMessage());
        }

    }
}
